5  Time Plot

Before start with this tutorial, please load lagci package first.

library(lagci)
Warning in fun(libname, pkgname): mzR has been built against a different Rcpp version (1.0.14)
than is installed on your system (1.1.0). This might lead to errors
when loading mzR. If you encounter such issues, please send a report,
including the output of sessionInfo() to the Bioc support forum at 
https://support.bioconductor.org/. For details see also
https://github.com/sneumann/mzR/wiki/mzR-Rcpp-compiler-linker-issue.
── Attaching packages ────────────────────────────────────────── lagci 0.99.5 ──
✔ dplyr   1.1.4     ✔ ggplot2 3.5.2
── Conflicts ────────────────────────────────────────────── lagci_conflicts() ──
✖ methods::body<-()    masks base::body<-()
✖ dplyr::filter()      masks stats::filter()
✖ methods::kronecker() masks base::kronecker()
✖ dplyr::lag()         masks stats::lag()

By using the time_plot function, you can obtain the visualization results of the time series.

This chunk creates a small, clean time series suitable for lagged-correlation demos.

It builds a datetime column as a POSIXct sequence from 2003-01-09 00:00:00 to 2003-01-10 00:00:00 at 10-minute intervals, then computes a smooth sine wave over the full range 0→2π0 →2π with exactly nrow(example_data_1) points, storing it in value.

Because seq(..., by = "10 min") controls the sampling, you get evenly spaced timestamps; the data are deterministic (no randomness), so results are reproducible. head(example_data_1) just previews the first few rows.

For downstream analysis, most lag tools expect columns named time (POSIXct) and value. You can simply rename with dplyr::rename(example_data_1, time = datetime), and—if you need cross-machine consistency—set an explicit timezone when creating the sequence (e.g., as.POSIXct(..., tz = "UTC")).

example_data_1 <- data.frame(
  datetime = seq(from = as.POSIXct("2003-01-09 00:00:00"),
                 to = as.POSIXct("2003-01-10 00:00:00"),
                 by = "10 min")
)

example_data_1$value <- sin(seq(from = 0, to = 2*pi,
                                length.out = nrow(example_data_1)))

head(example_data_1)
             datetime      value
1 2003-01-09 00:00:00 0.00000000
2 2003-01-09 00:10:00 0.04361939
3 2003-01-09 00:20:00 0.08715574
4 2003-01-09 00:30:00 0.13052619
5 2003-01-09 00:40:00 0.17364818
6 2003-01-09 00:50:00 0.21643961
time_plot(x = example_data_1$value,
          time = example_data_1$datetime,
          color = "green",
          y_axis_name = "y_axis",
          sun_rise_time = "6:00:00",
          sun_set_time = "18:00:00",
          time_gap = 6,
          add_point = FALSE,
          facet = FALSE)

time_plot(x = example_data_1$value,
          time = example_data_1$datetime,
          color = "blue",
          y_axis_name = "value",
          sun_rise_time = "8:00:00",
          sun_set_time = "20:00:00",
          time_gap = 1,
          add_point = FALSE,
          facet = TRUE)

time_plot(x = example_data_1$value,
          time = example_data_1$datetime,
          color = "red",
          y_axis_name = "name",
          sun_rise_time = "6:00:00",
          sun_set_time = "18:00:00",
          time_gap = 3,
          add_point = TRUE,
          facet = TRUE)

5.1 Session information

R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.0

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Asia/Singapore
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.5.2 dplyr_1.1.4   lagci_0.99.5 

loaded via a namespace (and not attached):
  [1] pbapply_1.7-4               remotes_2.5.0              
  [3] rlang_1.1.6                 magrittr_2.0.3             
  [5] clue_0.3-66                 GetoptLong_1.0.5           
  [7] matrixStats_1.5.0           compiler_4.5.1             
  [9] png_0.1-8                   vctrs_0.6.5                
 [11] reshape2_1.4.4              rvest_1.0.4                
 [13] stringr_1.5.1               ProtGenerics_1.40.0        
 [15] pkgconfig_2.0.3             MetaboCoreUtils_1.16.1     
 [17] shape_1.4.6.1               crayon_1.5.3               
 [19] fastmap_1.2.0               XVector_0.48.0             
 [21] labeling_0.4.3              rmarkdown_2.29             
 [23] tzdb_0.5.0                  UCSC.utils_1.4.0           
 [25] preprocessCore_1.70.0       purrr_1.1.0                
 [27] xfun_0.53                   MultiAssayExperiment_1.34.0
 [29] masstools_1.0.15            GenomeInfoDb_1.44.2        
 [31] jsonlite_2.0.0              DelayedArray_0.34.1        
 [33] BiocParallel_1.42.1         parallel_4.5.1             
 [35] cluster_2.1.8.1             R6_2.6.1                   
 [37] stringi_1.8.7               RColorBrewer_1.1-3         
 [39] limma_3.64.3                GenomicRanges_1.60.0       
 [41] lubridate_1.9.4             Rcpp_1.1.0                 
 [43] SummarizedExperiment_1.38.1 iterators_1.0.14           
 [45] knitr_1.50                  readr_2.1.5                
 [47] IRanges_2.42.0              BiocBaseUtils_1.10.0       
 [49] Matrix_1.7-3                igraph_2.1.4               
 [51] timechange_0.3.0            tidyselect_1.2.1           
 [53] rstudioapi_0.17.1           dichromat_2.0-0.1          
 [55] abind_1.4-8                 doParallel_1.0.17          
 [57] codetools_0.2-20            affy_1.86.0                
 [59] lattice_0.22-7              tibble_3.3.0               
 [61] plyr_1.8.9                  withr_3.0.2                
 [63] Biobase_2.68.0              evaluate_1.0.4             
 [65] Spectra_1.18.2              zip_2.3.3                  
 [67] xml2_1.4.0                  circlize_0.4.16            
 [69] pillar_1.11.0               affyio_1.78.0              
 [71] BiocManager_1.30.26         MatrixGenerics_1.20.0      
 [73] foreach_1.5.2               stats4_4.5.1               
 [75] MSnbase_2.34.1              MALDIquant_1.22.3          
 [77] ncdf4_1.24                  generics_0.1.4             
 [79] S4Vectors_0.46.0            hms_1.1.3                  
 [81] scales_1.4.0                glue_1.8.0                 
 [83] lazyeval_0.2.2              tools_4.5.1                
 [85] mzID_1.46.0                 QFeatures_1.18.0           
 [87] vsn_3.76.0                  mzR_2.42.0                 
 [89] openxlsx_4.2.8              XML_3.99-0.19              
 [91] fs_1.6.6                    grid_4.5.1                 
 [93] impute_1.82.0               tidyr_1.3.1                
 [95] massdataset_1.0.34          MsCoreUtils_1.20.0         
 [97] colorspace_2.1-1            GenomeInfoDbData_1.2.14    
 [99] PSMatch_1.12.0              cli_3.6.5                  
[101] S4Arrays_1.8.1              ComplexHeatmap_2.24.1      
[103] AnnotationFilter_1.32.0     pcaMethods_2.0.0           
[105] gtable_0.3.6                ggsci_3.2.0                
[107] digest_0.6.37               BiocGenerics_0.54.0        
[109] SparseArray_1.8.1           ggrepel_0.9.6              
[111] rjson_0.2.23                htmlwidgets_1.6.4          
[113] farver_2.1.2                htmltools_0.5.8.1          
[115] lifecycle_1.0.4             httr_1.4.7                 
[117] statmod_1.5.0               GlobalOptions_0.1.2        
[119] MASS_7.3-65